package fuse.LaCollaFS.Metadades;

import java.util.Calendar;
import java.util.List;

import org.jdom.Element;

import fuse.FuseStat;

public class Enllas extends Node {
	private String Original;

	public Enllas(String path) {
		this.setNom(path);
		this.defEnllas();
		Original ="";

	} 

	public void setOriginal(String i) {
		Original = i;
		
	}

	public String getOriginal() {

		return Original;
	}
	public void LlegirXML(Element root) {
		Element stat;
		this.setNom(root.getAttributeValue("Nom"));

	//	this.setPare(root.getAttributeValue("Pare"));
		this.setOriginal(root.getAttributeValue("To"));

		List l = root.getChildren();
		stat = (Element) l.get(0);
		// p("Stat Type: " + stat.getName());

		FuseStat estat;
		estat = this.getStat();
		// omplir stat.....
		estat.atime = Integer.valueOf(stat.getAttributeValue("atime"))
				.intValue();
		estat.blocks = Integer.valueOf(stat.getAttributeValue("blocks"))
				.intValue();
		estat.ctime = Integer.valueOf(stat.getAttributeValue("ctime"))
				.intValue();
		estat.gid = Integer.valueOf(stat.getAttributeValue("gid")).intValue();
	//	estat.inode = Integer.valueOf(stat.getAttributeValue("inode"))
	//			.intValue();
		estat.mode = Integer.valueOf(stat.getAttributeValue("mode")).intValue();
		estat.mtime = Integer.valueOf(stat.getAttributeValue("mtime"))
				.intValue();
		estat.nlink = Integer.valueOf(stat.getAttributeValue("nlink"))
				.intValue();
		estat.size = Integer.valueOf(stat.getAttributeValue("size")).intValue();
		estat.uid = Integer.valueOf(stat.getAttributeValue("uid")).intValue();
		this.setStat(estat);
		// p(" em dic " + this.getNom());
		
			

	}
	public Element CrearXML() {
		Element fill = new Element("Enllas");
	
		fill.setAttribute("Nom", this.getNom());
		fill.setAttribute("To", Original);
		//fill.setAttribute("VAnterior", this.VAnterior.getIdObjecte());
	//	fill.setAttribute("Versions", String.valueOf(this.Versions));
		
		Element estat = new Element("Stat");

		estat.setAttribute("atime", String.valueOf(this.getStat().atime));
		estat.setAttribute("blocks", String.valueOf(this.getStat().blocks));
		estat.setAttribute("ctime", String.valueOf(this.getStat().ctime));
		estat.setAttribute("gid", String.valueOf(this.getStat().gid));
//		estat.setAttribute("inode", String.valueOf(this.getStat().inode));
		estat.setAttribute("mode", String.valueOf(this.getStat().mode));
		estat.setAttribute("mtime", String.valueOf(this.getStat().mtime));
		estat.setAttribute("nlink", String.valueOf(this.getStat().nlink));
		estat.setAttribute("size", String.valueOf(this.getStat().size));
		estat.setAttribute("uid", String.valueOf(this.getStat().uid));
		fill.addContent(estat);
		
		if (this.getPare() == null) {
			p("node arrel, no te pare");
			fill.setAttribute("Pare", "/media/");
		} else
			fill.setAttribute("Pare", this.getPare().getNom());
		
		return fill;
	}
	private void p(Object o) {
		System.out.println(o); // TODO Auto-generated method stub

	}

}
